package com.server.questionbank.snframe.service.CourseService.Impl.Member;

import com.server.questionbank.snframe.domain.Course.Member.CusStudyGroup;
import com.server.questionbank.snframe.mapper.Course.Member.MemberGroupMapper;
import com.server.questionbank.snframe.service.CourseService.Member.CusMemberGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CusMemberGroupServiceImpl implements CusMemberGroupService {
    @Autowired
    private MemberGroupMapper cusStudyGroupMapper;

    // 创建课程学习分组
    @Override
    public boolean createCusStudyGroup(Long courseId, String groupName) {
        String _groupName = groupName;
        if (_groupName == null || _groupName.isEmpty()) _groupName = "新建班级";
        // 是否成功
        boolean isSuccess = false;
        if (cusStudyGroupMapper.getDefaultCusStudyGroupByCourseId(courseId) == null)
            if (cusStudyGroupMapper.getCusStudyGroupByCourseId(courseId).size() >  0)
                isSuccess = cusStudyGroupMapper.insertCusStudyGroup(courseId, _groupName, "Y") > 0;
            else
            {
                isSuccess = cusStudyGroupMapper.insertCusStudyGroup(courseId, "默认班级", "Y") > 0;
            }
        else isSuccess = cusStudyGroupMapper.insertCusStudyGroup(courseId, _groupName, "N") > 0;
        return isSuccess;
    }

    // 获取学习分组信息
    @Override
    public CusStudyGroup getCusStudyGroupById(Long groupId) {
        return cusStudyGroupMapper.getCusStudyGroupById(groupId);
    }

    // 获取课程的学习分组
    @Override
    public List<CusStudyGroup> getCusStudyGroupByCourseId(Long courseId) {
        return cusStudyGroupMapper.getCusStudyGroupByCourseId(courseId);
    }

    // 获取课程的默认学习分组
    @Override
    public CusStudyGroup getDefaultCusStudyGroupByCourseId(Long courseId) {
        return cusStudyGroupMapper.getDefaultCusStudyGroupByCourseId(courseId);
    }
}
